package com.example.guet_assistant.config;

import com.example.guet_assistant.handler.MyWebSocketHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 注册 WebSocket 端点
        registry.addHandler(new MyWebSocketHandler(), "/ws/messages")  // WebSocket端点
                .setAllowedOrigins("*"); // 允许所有来源访问
    }
}
